package leecode

func rangeSumBST(root *TreeNode, low int, high int) int {
	//中 左 右
	var traversal func(node *TreeNode, low int, high int) int
	traversal = func(node *TreeNode, low int, high int) (result int) {
		if node == nil {
			return
		}
		if node.Val > high {
			//左侧节点
			return traversal(node.Left, low, high)
		}
		if node.Val < low {
			//右侧节点
			return traversal(node.Right, low, high)
		}
		result = node.Val + traversal(node.Left, low, high) + traversal(node.Right, low, high)
		return
	}
	return traversal(root, low, high)
}
